﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace nicotool
{
   public class CustomWebClient : WebClient
    {
       /// <summary>
        /// CookieContainer属性 
       /// </summary>
       public CookieContainer CookieContainer { get; set; }

       /// <summary>
       /// CookieContainer数据初始化
       /// </summary>
       public CustomWebClient()
       {
           CookieContainer = new CookieContainer();
       }

       protected override WebRequest GetWebRequest(Uri address)
       {

           var request = base.GetWebRequest(address); //获得HttpWebRequest
           if (request is HttpWebRequest)   //判断request是否为空
           {
               (request as HttpWebRequest).CookieContainer = CookieContainer; //设置cookie
           }
          
           return request; //返回httpwebrequest
       }

    }
}
